package com.chexiehui.jc.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.blankj.utilcode.util.SizeUtils;
import com.chexiehui.jc.R;
import com.chexiehui.jc.utils.GlideUtil;
import com.lxj.xpopup.XPopup;

import java.util.List;

/**
 * 描述：
 * 作者：SongJun
 * 时间：2016/5/12
 */
public class NineGridTestLayout extends NineGridLayout {

    protected static final int MAX_W_H_RATIO = 3;

    public NineGridTestLayout(Context context) {
        super(context);
    }

    public NineGridTestLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean displayOneImage(final RatioImageView imageView, String url, final int parentWidth) {
       /* Glide.with(mContext).asBitmap().load(GlideUtil.getUrl(url)).dontAnimate()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
                        int w = bitmap.getWidth();
                        int h = bitmap.getHeight();

                        int newW;
                        int newH;
                        if (h > w * MAX_W_H_RATIO) {//h:w = 5:3
                            newW = parentWidth / 2;
                            newH = newW * 5 / 3;
                        } else if (h < w) {//h:w = 2:3
                            newW = parentWidth * 2 / 3;
                            newH = newW * 2 / 3;
                        } else {//newH:h = newW :w
                            newW = parentWidth / 2;
                            newH = h * newW / w;
                        }
                        setOneImageLayoutParams(imageView, newW, newH);
                    }
                });*/
        GlideUtil.loadImageViewCustomerRoundCrop(mContext, url, imageView, R.drawable.shape_round_5_gray, R.drawable.shape_round_5_gray, true, true, true, true, SizeUtils.dp2px(5));
        return false;
    }

    @Override
    protected void displayImage(RatioImageView imageView, String url) {
        GlideUtil.loadImageViewCustomerRoundCrop(mContext, url, imageView, R.drawable.shape_round_5_gray, R.drawable.shape_round_5_gray, true, true, true, true, SizeUtils.dp2px(5));
    }

    @Override
    protected void onClickImage(int i, String url, List urlList) {
        try {
            new XPopup.Builder(mContext).asImageViewer((ImageView) getChildAt(i), i, urlList,
                    (popupView, position) -> popupView.updateSrcView((ImageView) getChildAt(position)), new CustomXPopupImageLoader())
                    .show();
        }catch (Exception e){}
    }
}